import uicls
import uiconst
import uiutil
import uix
import blue
import log
import util
import trinity
import random
import uthread
IN_ICONS = {500001: 'ui_19_128_01',
 500002: 'ui_19_128_02',
 500004: 'ui_19_128_03',
 500003: 'ui_19_128_04'}
IN_CORP_ICONS = {500005: 'corps_39_128_03',
 500006: 'corps_26_128_03',
 500007: 'corps_44_128_04',
 500008: 'corps_45_128_03',
 500009: 'corps_27_128_02',
 500010: 'corps_28_128_03',
 500011: 'corps_45_128_02',
 500012: 'corps_19_128_03',
 500013: 'corps_03_128_02',
 500014: 'corps_27_128_04',
 500015: 'corps_44_128_03',
 500016: 'corps_14_128_01',
 500017: 'corps_36_128_02',
 500018: 'corps_34_128_02',
 500019: 'corps_44_128_02',
 500020: 'corps_45_128_01'}
IN_SMALL_ICONS = {500001: 'ui_75_32_01',
 500002: 'ui_75_32_02',
 500004: 'ui_75_32_03',
 500003: 'ui_75_32_04',
 500005: 'ui_75_32_05',
 500006: 'ui_75_32_06',
 500007: 'ui_75_32_07',
 500008: 'ui_75_32_08',
 500009: 'ui_75_32_09',
 500010: 'ui_75_32_10',
 500011: 'ui_75_32_11',
 500013: 'ui_75_32_12',
 500014: 'ui_75_32_13',
 500015: 'ui_75_32_14',
 500016: 'ui_75_32_15',
 500017: 'ui_75_32_16',
 500018: 'ui_75_32_17',
 500019: 'ui_75_32_18',
 500020: 'ui_75_32_19'}
RACE_ICONS = {const.raceCaldari: 'ui_88_128_01',
 const.raceMinmatar: 'ui_88_128_02',
 const.raceAmarr: 'ui_88_128_04',
 const.raceGallente: 'ui_88_128_03'}
CORP_ICONS = {1000002: 'corps_07_128_04',
 1000050: 'corps_41_128_03',
 1000051: 'corps_22_128_02',
 1000052: 'corps_22_128_01',
 1000053: 'corps_23_128_01',
 1000054: 'corps_22_128_04',
 1000055: 'corps_21_128_02',
 1000056: 'corps_23_128_02',
 1000057: 'corps_21_128_03',
 1000058: 'corps_23_128_03',
 1000059: 'corps_21_128_04',
 1000068: 'corps_18_128_03',
 1000060: 'corps_22_128_03',
 1000061: 'corps_23_128_04',
 1000062: 'corps_21_128_01',
 1000063: 'corps_14_128_03',
 1000064: 'corps_15_128_02',
 1000065: 'corps_14_128_02',
 1000066: 'corps_19_128_04',
 1000067: 'corps_16_128_01',
 1000069: 'corps_17_128_02',
 1000070: 'corps_19_128_01',
 1000079: 'corps_14_128_04',
 1000080: 'corps_17_128_01',
 1000071: 'corps_17_128_04',
 1000072: 'corps_16_128_02',
 1000073: 'corps_13_128_02',
 1000074: 'corps_15_128_04',
 1000075: 'corps_17_128_03',
 1000076: 'corps_13_128_03',
 1000077: 'corps_39_128_04',
 1000078: 'corps_18_128_04',
 1000082: 'corps_16_128_03',
 1000083: 'corps_15_128_01',
 1000084: 'corps_16_128_04',
 1000085: 'corps_18_128_01',
 1000086: 'corps_12_128_01',
 1000087: 'corps_13_128_01',
 1000088: 'corps_12_128_03',
 1000089: 'corps_12_128_02',
 1000090: 'corps_12_128_04',
 1000091: 'corps_15_128_03',
 1000092: 'corps_13_128_04',
 1000081: 'corps_18_128_02',
 1000093: 'corps_19_128_02',
 1000094: 'corps_33_128_01',
 1000095: 'corps_33_128_03',
 1000096: 'corps_26_128_01',
 1000097: 'corps_31_128_03',
 1000098: 'corps_28_128_02',
 1000099: 'corps_27_128_03',
 1000100: 'corps_34_128_03',
 1000101: 'corps_32_128_03',
 1000102: 'corps_29_128_04',
 1000103: 'corps_25_128_04',
 1000114: 'corps_25_128_01',
 1000104: 'corps_25_128_02',
 1000105: 'corps_38_128_02',
 1000106: 'corps_25_128_03',
 1000107: 'corps_31_128_02',
 1000108: 'corps_32_128_01',
 1000109: 'corps_32_128_04',
 1000110: 'corps_33_128_02',
 1000111: 'corps_30_128_01',
 1000112: 'corps_31_128_04',
 1000113: 'corps_32_128_02',
 1000124: 'corps_24_128_03',
 1000125: 'corps_26_128_03',
 1000115: 'corps_39_128_01',
 1000116: 'corps_30_128_02',
 1000117: 'corps_30_128_04',
 1000118: 'corps_29_128_01',
 1000119: 'corps_29_128_02',
 1000120: 'corps_29_128_03',
 1000121: 'corps_30_128_03',
 1000122: 'corps_31_128_01',
 1000123: 'corps_35_128_02',
 1000134: 'corps_19_128_03',
 1000135: 'corps_38_128_01',
 1000136: 'corps_24_128_02',
 1000126: 'corps_35_128_03',
 1000127: 'corps_28_128_03',
 1000128: 'corps_34_128_02',
 1000129: 'corps_27_128_04',
 1000130: 'corps_14_128_01',
 1000131: 'corps_36_128_02',
 1000132: 'corps_03_128_04',
 1000133: 'corps_24_128_01',
 1000137: 'corps_04_128_01',
 1000138: 'corps_24_128_04',
 1000139: 'corps_35_128_04',
 1000140: 'corps_40_128_02',
 1000141: 'corps_28_128_04',
 1000142: 'corps_40_128_04',
 1000143: 'corps_26_128_04',
 1000144: 'corps_26_128_02',
 1000145: 'corps_27_128_01',
 1000146: 'corps_28_128_01',
 1000147: 'corps_27_128_02',
 1000148: 'corps_03_128_02',
 1000149: 'corps_40_128_03',
 1000150: 'corps_39_128_03',
 1000151: 'corps_11_128_04',
 1000152: 'corps_11_128_02',
 1000153: 'corps_11_128_03',
 1000154: 'corps_35_128_01',
 1000155: 'corps_41_128_01',
 1000156: 'corps_11_128_01',
 1000157: 'corps_33_128_04',
 1000158: 'corps_40_128_01',
 1000159: 'corps_36_128_03',
 1000160: 'corps_36_128_01',
 1000161: 'corps_34_128_04',
 1000162: 'corps_34_128_01',
 1000163: 'corps_36_128_04',
 1000164: 'corps_41_128_02',
 1000003: 'corps_01_128_03',
 1000004: 'corps_08_128_01',
 1000005: 'corps_01_128_04',
 1000006: 'corps_04_128_04',
 1000007: 'corps_38_128_03',
 1000008: 'corps_39_128_02',
 1000009: 'corps_03_128_03',
 1000010: 'corps_03_128_01',
 1000011: 'corps_06_128_02',
 1000012: 'corps_10_128_04',
 1000013: 'corps_09_128_04',
 1000014: 'corps_07_128_02',
 1000015: 'corps_01_128_01',
 1000016: 'corps_05_128_04',
 1000017: 'corps_02_128_04',
 1000018: 'corps_05_128_03',
 1000019: 'corps_06_128_01',
 1000020: 'corps_02_128_01',
 1000021: 'corps_02_128_03',
 1000022: 'corps_05_128_02',
 1000023: 'corps_09_128_01',
 1000024: 'corps_07_128_03',
 1000025: 'corps_10_128_03',
 1000026: 'corps_08_128_04',
 1000027: 'corps_09_128_02',
 1000028: 'corps_09_128_03',
 1000029: 'corps_04_128_02',
 1000030: 'corps_05_128_01',
 1000031: 'corps_08_128_02',
 1000032: 'corps_07_128_01',
 1000033: 'corps_08_128_03',
 1000034: 'corps_04_128_03',
 1000035: 'corps_37_128_03',
 1000036: 'corps_01_128_02',
 1000037: 'corps_02_128_02',
 1000038: 'corps_06_128_03',
 1000039: 'corps_37_128_02',
 1000040: 'corps_37_128_01',
 1000041: 'corps_38_128_04',
 1000042: 'corps_06_128_04',
 1000043: 'corps_37_128_04',
 1000044: 'corps_10_128_01',
 1000045: 'corps_10_128_02',
 1000046: 'corps_20_128_03',
 1000047: 'corps_20_128_01',
 1000048: 'corps_20_128_04',
 1000049: 'corps_20_128_02',
 1000165: 'corps_43_128_01',
 1000166: 'corps_42_128_03',
 1000167: 'corps_42_128_01',
 1000168: 'corps_42_128_04',
 1000169: 'corps_41_128_04',
 1000170: 'corps_43_128_02',
 1000171: 'corps_43_128_03',
 1000172: 'corps_43_128_04',
 1000173: 'corps_44_128_01',
 1000178: 'corps_46_128_02',
 1000179: 'corps_47_128_01',
 1000180: 'corps_47_128_02',
 1000181: 'corps_47_128_03',
 1000182: 'corps_47_128_04',
 109299958: 'corps_46_128_01',
 1000177: 'corps_45_128_04'}
STRAGEGIC_CRUISER_BLUEPRINT_ICON_MAP = {29984: 'ui_106_128_1',
 29986: 'ui_106_128_2',
 29990: 'ui_106_128_3',
 29988: 'ui_106_128_4'}

class EveIcon(uicls.IconCore):
    __guid__ = 'uicls.Icon'
    size_doc = 'Optional icon pixel size. Will override width and height with size.'
    typeID_doc = 'Optional param to override the icon path.  Will get a type based icon instead.'
    itemID_doc = "Optional param for char portraits or 'location' icons. Used with typeID."
    iconID_doc = 'Optional param when referencing an icon graphic ID as in cfg.icons'
    path_doc = 'Optional fullpath for a icon texture.  Uses rect param to define cropping area if included'
    rect_doc = 'Optional param to define the texture area to use when path is being used'
    default_size = None
    default_typeID = None
    default_itemID = None
    default_iconID = None
    default_path = None
    default_rect = (0, 0, 0, 0)
    default_width = None
    default_height = None
    TYPE_DISALLOWED_GROUPS = (const.groupCargoContainer,
     const.groupSecureCargoContainer,
     const.groupAuditLogSecureContainer,
     const.groupFreightContainer,
     const.groupHarvestableCloud,
     const.groupAsteroidBelt,
     const.groupTemporaryCloud,
     const.groupPlanetaryLinks)
    TYPE_ALLOWED_GROUPS = (const.groupCharacter,
     const.groupStation,
     const.groupStargate,
     const.groupWreck)
    TYPE_ALLOWED_CATEGORIES = (const.categoryCelestial,
     const.categoryShip,
     const.categoryStation,
     const.categoryEntity,
     const.categoryDrone,
     const.categoryDeployable,
     const.categoryStructure,
     const.categorySovereigntyStructure,
     const.categoryPlanetaryInteraction,
     const.categoryOrbital)

    def ApplyAttributes(self, attributes):
        if (attributes.__gotShape__ and (len(attributes.keys()) == 1)):
            return 
        size = attributes.get('size', self.default_size)
        if (attributes.get('align', self.default_align) != uiconst.TOALL):
            size = attributes.get('size', self.default_size)
            if size:
                attributes.width = attributes.height = size
        else:
            attributes.pos = (0, 0, 0, 0)
            attributes.width = attributes.height = 0
        icon = attributes.get('icon', self.default_icon)
        if ('icon' in attributes):
            del attributes['icon']
        uicls.IconCore.ApplyAttributes(self, attributes)
        self.ChangeIcon(icon=icon, **attributes)



    def ChangeIcon(self, **kw):
        tripass = None
        isBlueprint = False
        typeID = None
        graphic = None
        icon = kw.get('icon', self.default_icon)
        size = kw.get('size', self.default_size)
        iconID = kw.get('iconID', self.default_iconID)
        typeID = kw.get('typeID', self.default_typeID)
        path = kw.get('path', self.default_path)
        ignoreSize = kw.get('ignoreSize', self.default_ignoreSize)
        if icon:
            if icon.startswith('c_'):
                (c, sheet, num,) = icon.split('_')
                icon = ('corps_%s_128_%s' % (sheet, num))
        elif iconID:
            graphic = cfg.icons.Get(iconID)
        elif typeID:
            group = None
            invtype = cfg.invtypes.GetIfExists(typeID)
            if invtype:
                graphic = invtype.Icon()
                group = invtype.Group()
                if (group.categoryID == const.categoryBlueprint):
                    isBlueprint = True
                    typeID = cfg.invbptypes.Get(typeID).productTypeID
                    invtype = cfg.invtypes.Get(typeID)
                    graphic = invtype.Icon()
                    group = invtype.Group()
            if (group is not None):
                itemID = kw.get('itemID', self.default_itemID)
                if (itemID and (group.id in (const.groupRegion,
                 const.groupConstellation,
                 const.groupSolarSystem))):
                    if not (util.IsSolarSystem(itemID) or (util.IsConstellation(itemID) or util.IsRegion(itemID))):
                        log.LogError('Not valid itemID for 2D map, itemID: ', itemID, ', typeID: ', typeID)
                        log.LogTraceback()
                    level = ([const.groupRegion,
                     const.groupConstellation,
                     const.groupSolarSystem].index(group.id) + 1)
                    imagePath = sm.GetService('photo').Get2DMap([itemID], level, (level + 1), (size or 256))
                    if imagePath:
                        self.LoadTexture(imagePath)
                        if (group.id == const.groupSolarSystem):
                            tripass = blue.rot.GetInstance('res:/ui/pass/linear.blue')
                        else:
                            tripass = blue.rot.GetInstance('res:/UI/Pass/map.blue')
                    else:
                        icon = 'ui_9_64_14'
                elif ((group.id in (const.groupStrategicCruiser)) or ((not itemID) and (group.id in (const.groupPlanet, const.groupMoon)))):
                    if (isBlueprint and (group.id == const.groupStrategicCruiser)):
                        icon = STRAGEGIC_CRUISER_BLUEPRINT_ICON_MAP[typeID]
                        graphic = None
                    elif graphic:
                        icon = graphic.iconFile
                    else:
                        icon = 'ui_7_64_15'
                else:
                    if (((typeID == const.typePlanetaryLaunchContainer) or (group.id not in self.TYPE_DISALLOWED_GROUPS)) and ((group.id in self.TYPE_ALLOWED_GROUPS) or (group.categoryID in self.TYPE_ALLOWED_CATEGORIES))):
                        tripass = eve.rot.GetInstance('res:/UI/Pass/linear_noalpha.blue')
                        if (group.id == const.groupCharacter):
                            sm.GetService('photo').GetPortrait(itemID, size, self)
                        else:
                            sm.GetService('photo').OrderByTypeID([(typeID,
                              self,
                              (size or 64),
                              itemID,
                              isBlueprint,
                              kw.get('isCopy', False))])
                            isBlueprint = False
                        graphic = icon = None
        if (graphic and (graphic.iconFile not in ('', None))):
            iconFile = graphic.iconFile.strip()
            if iconFile.startswith('res:/'):
                path = iconFile
                icon = None
            else:
                path = None
            icon = iconFile
        if not ignoreSize:
            if (self.GetAlign() != uiconst.TOALL):
                pos = kw.get('pos', self.default_pos)
                if pos:
                    (self.width, self.heigth,) = (pos[2], pos[3])
                if size:
                    self.width = self.height = size
                width = kw.get('width', self.default_width)
                if (width is not None):
                    self.width = width
                height = kw.get('height', self.default_height)
                if (height is not None):
                    self.height = height
            else:
                self.width = self.height = 0
        if path:
            self.MapIconFromPath(path, kw.get('rect', self.default_rect))
        elif icon:
            if icon[0].isdigit():
                parts = icon.split('_')
                if (len(parts) == 2):
                    old = icon
                    icon = uix.GetIconPath(icon)
            uiutil.MapIcon(self, icon, ignoreSize)
        if (typeID and isBlueprint):
            sm.GetService('photo').DoBlueprint(self, typeID, size=64, isCopy=kw.get('isCopy', False))
        if tripass:
            self.tripass = tripass
        else:
            self.UpdatePixelFilter()



    def UpdatePixelFilter(self):
        (l, t, w, h,) = self.GetAbsolute()
        if (w == self.rectWidth):
            self.tripass = None
        else:
            self.tripass = blue.rot.GetInstance('res:/ui/pass/linear.blue')



    def MapIconFromPath(self, resPath, rect = (0, 0, 0, 0)):
        if (resPath is None):
            raise RuntimeError, 'resPath must be a valid resource path'
        if resPath.endswith('.blue'):
            texture = blue.os.LoadObject(resPath)
            self.rectWidth = int((texture.scaling.x * 256.0))
            self.rectHeight = int((texture.scaling.y * 256.0))
            self.rectLeft = int((texture.translation.x * 256.0))
            self.rectTop = int((texture.translation.y * 256.0))
            self.texture.pixels = texture.pixels
        elif resPath.endswith('.red'):
            texture = trinity.Load(resPath)
            self.rectWidth = int((texture.scaling.x * 256.0))
            self.rectHeight = int((texture.scaling.y * 256.0))
            self.rectLeft = int((texture.translation.x * 256.0))
            self.rectTop = int((texture.translation.y * 256.0))
            self.texture.pixels = texture.pixels
        elif rect:
            (t, l, w, h,) = rect
            self.texture = None
            self.texture = trinity.TriTexture()
            self.texture.pixels = resPath
            self.rectWidth = int(w)
            self.rectHeight = int(h)
            self.rectLeft = int(l)
            self.rectTop = int(t)
        else:
            raise RuntimeError, 'rect must be set if not using .red or .blue files'




class DraggableIcon(uicls.Container):
    __guid__ = 'uicls.DraggableIcon'
    __resPath__ = 'res:/UI/Component/icon_draggable.blue'
    default_name = 'draggableIcon'
    default_opacity = 1.0

    def ApplyAttributes(self, attributes):
        uicls.Container.ApplyAttributes(self, attributes)
        attrs = attributes.Copy()
        if ('parent' in attrs):
            del attrs['parent']
        self.ChangeIcon(**attrs)



    def ChangeIcon(self, typeID = None, itemID = None, icon = None, size = 64, isCopy = False, **kw):
        subpar = self.children[0]
        for c in subpar.children[:]:
            if (c.name == 'icon'):
                subpar.children.remove(c)

        EveIcon(parent=subpar, name='icon', idx=1, typeID=typeID, itemID=itemID, icon=icon, size=size, ignoreSize=True, isCopy=isCopy)




class LogoIcon(EveIcon):
    __guid__ = 'uicls.LogoIcon'
    default_isSmall = None
    default_isSmall_doc = 'Should we use the small version for faction icons.'
    default_align = uiconst.RELATIVE

    def ApplyAttributes(self, attributes):
        itemID = attributes.get('itemID', None)
        icon = None
        if (itemID is not None):
            if util.IsCorporation(itemID):
                if CheckCorpID(itemID):
                    icon = CORP_ICONS[itemID]
                else:
                    raise ValueError, 'LogoIcon class does not support custom corp icons.  Use CorpIcon for that'
            elif util.IsAlliance(itemID):
                raise ValueError, 'LogoIcon class does not support Alliance Logos.  Use GetLogoIcon or GetOwnerIcon'
            elif util.IsFaction(itemID):
                isSmall = attributes.get('isSmall', self.default_isSmall)
                icon = self.GetFactionIconID(itemID, isSmall)
            else:
                if (itemID in RACE_ICONS):
                    icon = RACE_ICONS[itemID]
        if (icon is None):
            icon = 'uicore_1_16_256'
        attributes['icon'] = icon
        EveIcon.ApplyAttributes(self, attributes)



    def GetFactionIconID(self, factionID, isSmall):
        if (isSmall and (factionID in IN_SMALL_ICONS)):
            return IN_SMALL_ICONS.get(factionID)
        if (factionID in IN_ICONS):
            return IN_ICONS.get(factionID)
        if (factionID in IN_CORP_ICONS):
            return IN_CORP_ICONS.get(factionID)




class CorpIcon(uicls.Container):
    __guid__ = 'uicls.CorpIcon'
    default_pos = (0, 0, 128, 128)
    default_size = None
    size_doc = 'Optional icon pixel size. Will override width and height with size.'
    default_name = 'corplogo'
    default_state = uiconst.UI_DISABLED
    default_align = uiconst.TOPLEFT
    __resPath__ = 'res:/UI/Component/corplogo.blue'

    def ApplyAttributes(self, attributes):
        if (attributes.get('align', self.default_align) != uiconst.TOALL):
            size = attributes.get('size', self.default_size)
            if size:
                attributes.width = attributes.height = size
        else:
            attributes.pos = (0, 0, 0, 0)
            attributes.width = attributes.height = 0
        uicls.Container.ApplyAttributes(self, attributes)
        corpID = attributes.get('corpID', None)
        if attributes.dontUseThread:
            self.DoLayout(corpID, attributes)
        else:
            uthread.new(self.DoLayout, corpID, attributes)



    def DoLayout(self, corpID, attributes):
        big = attributes.get('big', False)
        acceptNone = attributes.get('acceptNone', True)
        onlyValid = attributes.get('onlyValid', False)
        logoData = attributes.get('logoData', None)
        if (corpID in CORP_ICONS):
            return CORP_ICONS[corpID]
        if (logoData is None):
            if not corpID:
                if acceptNone:
                    return 
            else:
                logoData = cfg.corptickernames.Get(corpID)
        if logoData:
            log.LogInfo('LogoIcon.GetCorpIconID', 'corpID:', corpID, 'shape1:', logoData.shape1, 'shape2:', logoData.shape2, 'shape3:', logoData.shape3, 'color1:', logoData.color1, 'color2:', logoData.color2, 'color3:', logoData.color3)
            shapes = (logoData.shape1,
             logoData.shape2,
             logoData.shape3)
            if not (logoData.shape1 or (logoData.shape2 or logoData.shape3)):
                if acceptNone:
                    return 
                graphicFile = util.GraphicFile(random.randint(416, 512))
                self.children[0].control.model.areas[0].areaTextures[0] = trinity.Load(graphicFile)
            colors = (logoData.color1,
             logoData.color2,
             logoData.color3)
            for (i, shape,) in enumerate(shapes):
                if ((shape is not None) and (shape == int(shape))):
                    graphicFile = util.GraphicFile(shape)
                    if big:
                        graphicFile = ('%s/large/%s' % tuple(graphicFile.rsplit('/', 1)))
                    self.children[i].control.model.areas[0].areaTextures[0] = trinity.Load(graphicFile)
                    color = colors[i]
                    if ((color is not None) and (color == int(color))):
                        newshader = blue.rot.GetInstance(util.GraphicFile(color))
                        self.children[i].control.model.areas[0].shader = newshader
                        self.children[i].control.model.areas[0].shader.shaderMaterials[0].emissive = newshader.shaderMaterials[0].diffuse
                self.children[i].state = uiconst.UI_DISABLED

        elif onlyValid:
            raise RuntimeError('not valid corpID')




def CheckCorpID(corpID):
    return (corpID in CORP_ICONS)



def GetLogoIcon(itemID = None, **kw):
    if util.IsAlliance(itemID):
        logo = uicls.Icon(icon=None, **kw)
        sm.GetService('photo').GetAllianceLogo(itemID, 128, logo)
        return logo
    else:
        if ((not util.IsCorporation(itemID)) or CheckCorpID(itemID)):
            return LogoIcon(itemID=itemID, **kw)
        return CorpIcon(corpID=itemID, **kw)



def GetOwnerLogo(parent, ownerID, size = 64, noServerCall = False, callback = False, orderIfMissing = True):
    if (util.IsCharacter(ownerID) or util.IsAlliance(ownerID)):
        logo = uicls.Icon(icon=None, parent=parent, pos=(0,
         0,
         size,
         size), ignoreSize=True)
        if util.IsAlliance(ownerID):
            path = sm.GetService('photo').GetAllianceLogo(ownerID, 128, logo, callback=callback, orderIfMissing=orderIfMissing)
        else:
            path = sm.GetService('photo').GetPortrait(ownerID, size, logo, callback=callback, orderIfMissing=orderIfMissing)
        return (path is not None)
    else:
        if (util.IsCorporation(ownerID) or util.IsFaction(ownerID)):
            uiutil.GetLogoIcon(itemID=ownerID, parent=parent, pos=(0,
             0,
             size,
             size), ignoreSize=True)
        else:
            raise RuntimeError(('ownerID %d is not of an owner type!!' % ownerID))
        return True



class InfoIcon(EveIcon):
    __guid__ = 'uicls.InfoIcon'
    default_size = 16
    default_abstractinfo = None
    default_typeID = None
    default_itemID = None

    def ApplyAttributes(self, attributes):
        size = attributes.get('size', self.default_size)
        itemID = attributes.get('itemID', self.default_itemID)
        typeID = attributes.get('typeID', self.default_typeID)
        abstractinfo = attributes.get('abstractinfo', self.default_abstractinfo)
        icon = ('ui_38_16_208' if (size <= 16) else 'ui_09_64_09')
        attributes['icon'] = icon
        EveIcon.ApplyAttributes(self, attributes)
        self.OnClick = (self.ShowInfo,
         typeID,
         itemID,
         abstractinfo)



    def ShowInfo(self, typeID, itemID, abstractinfo, *args):
        sm.GetService('info').ShowInfo(typeID=typeID, itemID=itemID, abstractinfo=abstractinfo)




class PreviewIcon(EveIcon):
    __guid__ = 'uicls.PreviewIcon'
    default_size = 16
    default_typeID = None

    def ApplyAttributes(self, attributes):
        typeID = attributes.get('typeID', self.default_typeID)
        icon = 'ui_38_16_89'
        attributes['icon'] = icon
        EveIcon.ApplyAttributes(self, attributes)
        self.OnClick = (self.Preview, typeID)



    def Preview(self, typeID, *args):
        sm.GetService('preview').PreviewType(typeID)




class MenuIcon(EveIcon):
    __guid__ = 'uicls.MenuIcon'
    default_size = 16

    def ApplyAttributes(self, attributes):
        size = attributes.get('size', self.default_size)
        if (size <= 16):
            icon = 'ui_73_16_50'
        else:
            icon = 'ui_77_32_49'
        attributes['icon'] = icon
        EveIcon.ApplyAttributes(self, attributes)
        self.SetAlpha(0.8)
        self.expandOnLeft = 1



    def _OnMouseEnter(self, *args):
        self.SetAlpha(1.0)



    def _OnMouseExit(self, *args):
        self.SetAlpha(0.8)



exports = {'uiutil.GetLogoIcon': GetLogoIcon,
 'uiutil.CheckCorpID': CheckCorpID,
 'uiutil.GetOwnerLogo': GetOwnerLogo}

